package com.itheima_01;

public class MethodDemo3 {
    public static void main(String[] args) {
        //方法重载特点
        /*int sum1 = sum(10,20);
        System.out.println(sum1);
        double sum2 = sum(10.0,20.0);
        System.out.println(sum2);
        int sum3 = sum(10,20,30);
        System.out.println(sum3);*/

        //方法重载练习
        System.out.println(compare(1,2));//默认整数为int类型
        System.out.println(compare((byte)2,(byte)2));//强制类型转换
        System.out.println(compare((short)1,(short)2));//强制类型转换
        System.out.println(compare(2L,2L));//强制类型转换
    }

    //需求1：求2个int类型数据和的方法
    public static int sum(int a, int b) {
        return a + b;
    }

    //需求2：求2个double类型数据和的方法
    public static double sum(double a, double b) {
        return a + b;
    }

    //需求3：求3个int类型数据和的方法
    public static int sum(int a, int b, int c) {
        return a + b + c;
    }

    //需求4：使用方法重载的思想，设计比较两个整数是否相同的方法，兼容全部整数类型（byte，short，int，long）
    public static boolean compare(byte a, byte b) {
        System.out.println("byte");
        return a == b;
        /*if (a == b) {
            return true;
        } else {
            return false;
        }*/
    }

    public static boolean compare(short a, short b) {
        System.out.println("short");
        return a == b;
        /*if (a == b) {
            return true;
        } else {
            return false;
        }*/
    }
    public static boolean compare(int a, int b) {
        System.out.println("int");
        return a == b;
        /*if (a == b) {
            return true;
        } else {
            return false;
        }*/
    }
    public static boolean compare(long a, long b) {
        System.out.println("long");
        return a == b;
        /*if (a == b) {
            return true;
        } else {
            return false;
        }*/
    }
}
